import React, {Component} from 'react'
import PropTypes from 'prop-types'
import classNames from 'classnames'

/**
 * 按钮
 */

const BUTTON_PROPS_BLACKLIST = [
    'children',
    'dispatch',
    'state'
];
const cleanButtonProps = (ButtonProps) => {
    BUTTON_PROPS_BLACKLIST.forEach(field => delete ButtonProps[field]);
    return ButtonProps;
}

class Button extends Component {

    render(){
        let {id,children,className} = this.props

        className = classNames({[`${id}`]: id}, className)

        let { ...buttonProps } = this.props

        cleanButtonProps(buttonProps)

        buttonProps.className = className

        return (
            <button {...buttonProps}>{children}</button>
        )
    }
}
Button.defaultProps = {
    disabled: false,
}
Button.propTypes = {
    disabled: PropTypes.bool,
    id: PropTypes.string,
    onClick: PropTypes.func
}
export default  Button